<?php
/**
 *  系统给玩家发送邮件
 */

class SendEmailToUser extends APIBase {
	public $tag = "SendEmailToUser";
	public $isLogin = false;
	
	public function before() {
		$this->initMysql();
		$this->inithttp();
		$this->initCacheRedis();
		return true;
	}
			
	public function logic() {
	    $uid = $this->uid;
		$uidArr = array();
		$row = $this->mysql->find('select id from player');
        for($i=0;$i<count($row);$i++){
		    $keys = $this->cache_redis->keys('hemailbyuser:'.$row[$i]['id'].':*');
			//如果用户尚未存在邮箱
			$data = array('uid'=>$row[$i]['id'],'mid'=>1,'is_read'=>0,'is_receive'=>0,'send_date'=>time(),'update_date'=>time(),'sender'=>'系统');
		    if(count($keys)<=0){
				$this->cache_redis->hMset('hemailbyuser:'.$row[$i]['id'].':1',$data);
			}else{
				$count = count($keys)+1;
				$this->cache_redis->hMset('hemailbyuser:'.$row[$i]['id'].':'.$count,$data);
			}
	   }
			$this->returnData('success!!');
		
	}

	public function after() {
		$this->deinitCacheRedis();
		$this->deinitMysql();
	}
}

?>
